import { baseUrl } from '@/config/env';
import { BaseService } from '@/cool';
import store from '@/store';

export default class extends BaseService {
	constructor() {
		super();
		this.userUpdate = this.userUpdate.bind(this);
	}
	/**
	 * 文件上传
	 *
	 * @returns
	 * @memberof CommonService
	 */
	upload() {
		return {
			url: baseUrl + '/comm/upload',
			token: store.state.user.token
		};
	}

	// 用户注册
	regist(params) {
		return this.request({
			url: '/comm/regist',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	// 绑定邀请码
	bindInviteCode(params) {
		return this.request({
			url: '/comm/bindInviteCode',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	// 找回密码
	forget(params) {
		return this.request({
			url: '/comm/fogetPwd',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	/**
	 * 密码登录
	 *
	 * @param {*} { username, password, captchaId, verifyCode }
	 * @returns
	 * @memberof CommonService
	 */
	userLogin({ username, password, captchaId, verifyCode }) {
		return this.request({
			url: '/comm/loginByUser',
			method: 'POST',
			data: {
				username,
				password,
				captchaId,
				verifyCode
			}
		});
	}

	/**
	 * 用户退出
	 */
	userLogout() {
		return this.request({
			url: '/comm/logout',
			method: 'POST'
		});
	}

	/**
	 * 用户信息
	 *
	 * @returns
	 * @memberof CommonService
	 */
	userInfo() {
		return this.request({
			url: '/comm/person'
		});
	}

	/**
	 * 用户信息修改
	 *
	 * @param {*} params
	 * @returns
	 * @memberof CommonService
	 */
	userUpdate(params) {
		return this.request({
			url: '/comm/person-update',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	/**
	 * 权限信息
	 *
	 * @returns
	 * @memberof CommonService
	 */
	permMenu() {
		return this.request({
			url: '/comm/permmenu'
		});
	}

	/**
	 * 图片验证码 svg
	 *
	 * @param {*} { height, width }
	 * @returns
	 * @memberof CommonService
	 */
	captcha({ height, width }) {
		return this.request({
			url: '/comm/captcha',
			params: {
				height,
				width
			}
		});
	}

	/**
	 * 获取微信二维码
	 *
	 * @param {*} {}
	 * @returns
	 * @memberof CommonService
	 */
	qrcode(params) {
		return this.request({
			url: '/comm/qrcode',
			params: {
				...params
			}
		});
	}

	/**
	 * 绑定微信二维码
	 *
	 * @param {*} {}
	 * @returns
	 * @memberof CommonService
	 */
	bindWechat(params) {
		return this.request({
			url: '/comm/bindWechat',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	/**
	 * 校验微信二维码
	 *
	 * @param {*} { ticket }
	 * @returns
	 * @memberof CommonService
	 */
	wechatLogin(params) {
		return this.request({
			url: '/comm/wechatLogin',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	/**
	 * 获取短信验证码
	 *
	 * @param {*} { phone, phone, verifyCode }
	 * @returns
	 * @memberof CommonService
	 */
	smsCode(params) {
		return this.request({
			url: '/comm/getSmsCode',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	/**
	 * 短信验证码登录
	 *
	 * @param {*} { phone, code }
	 * @returns
	 */
	smsLogin(params) {
		return this.request({
			url: '/comm/smsLogin',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	// 获取配置
	getall(params) {
		return this.request({
			url: '/app/param/getall',
			params: {
				...params
			}
		});
	}
	async getParams(key) {
		const list = await this.request({
			url: '/app/param/getall'
		});

		return list.find(e => e.keyWord == key);
	}
	// 修改密码
	modifyPwd(params) {
		return this.request({
			url: '/comm/modifyPwd',
			method: 'POST',
			data: {
				...params
			}
		});
	}
	// 校验密码手机号
	modifyPhone(params) {
		return this.request({
			url: '/comm/modifyPhone',
			method: 'POST',
			data: {
				...params
			}
		});
	}
	// 通过手机验证码修改密码
	modifyPwdByPhone(params) {
		return this.request({
			url: '/comm/modifyPwdByPhone',
			method: 'POST',
			data: {
				...params
			}
		});
	}
	// 修改手机号
	checkPhone(params) {
		return this.request({
			url: '/comm/checkPhone',
			method: 'POST',
			data: {
				...params
			}
		});
	}
	// 绑定手机号
	bindPhone(params) {
		return this.request({
			url: '/comm/bindPhone',
			method: 'POST',
			data: {
				...params
			}
		});
	}

	// 绑定微信结果查询
	wechatResult(params) {
		return this.request({
			url: '/comm/wechatResult',
			method: 'POST',
			data: {
				...params
			}
		});
	}
	// 获取邀请码
	getInviteCode(params) {
		return this.request({
			url: '/comm/getInviteCode',
			params: {
				...params
			}
		});
	}

	// 获取下级组织
	belowDepartments(params) {
		return this.request({
			url: '/comm/belowDepartments',
			params: {
				...params
			}
		});
	}
}
